<template>
	<view class="box">
		<view style="display: flex;flex-direction: row;">
			<view v-if="mode==1">
				<!--<image src="/static/logo.png" style="width: 80px;height: 100rpx;margin-right: 10px;"></image>-->
				<image :src="showImage" style="width: 80px;height: 100rpx;margin-right: 10px;"
				@error="handlerImageException()"></image>
			</view>
			<text class="titlebox">{{ title }}</text>
		</view>
		<view class="adbox"v-if="mode==3"style="margin-top: 5rpx;">
			<view v-for="(item,index) in image">
				<image :src="item"mode="aspectFill"@error="handlerImageError(index)"></image>
			</view>
		</view>
		<view class="tipsbox">
			<text class="top-tag" v-if="isTop">置顶</text>
			<text class="author">{{ author }}</text>
			<text class="comments">{{ comments }}评</text>
			<text class="time">{{ time }}</text>
		</view>
		<slot name="tips"></slot>
	</view>
</template>

<script>
	export default {
		name: "cardViewText",
		props: {
			nID:{
				type:String,
				default:"000",
				require:true
			},
			title: {
				type: String,
				default: "新闻标题",
				require: true
			},
			isTop: {
				type: Boolean,
				default: false,
				require: true
			},
			author: {
				type: String,
				default: "来源",
				require: true
			},
			comments: {
				type: Number,
				default: 0,
				require: true
			},
			time: {
				type: String,
				default: "2025.11.01"
			},
			mode: {
				type: Number,
				default: 1
			},
			image: {
				type: Array,
				default: ()=>[]
			}
		},
		data() {
			return {
				defaultImage: "/static/logo.png",
				failImage: "/static/fail.png",
				imageError: false
			};
		},
		//计算属性
		computed: {
			showImage() {
				if (this.image) {
					if (this.imageError) {
						console.log("handlerImageError:" + this.nid + this.title);
						return this.failImage
					}
					return this.image
				} else {
					console.log("showImage defaultImage:" + this.nid + this.title);
					return this.defaultImage
				}
			}
		},
		methods: {
			handlerImageException(){
				console.log("handleImageException"+this.title);
				this.imageError = true;
			},
			handlerImageError(index) {
				console.log("handlerImageError:" + this.title);
				console.log("handlerImageError----->index:"+index);
				this.imageError = true;
			}
		}
	};
</script>

<style scoped>
	.adbox{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}
	.box {
		padding: 20rpx;
		margin-bottom: 15rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
	}

	.titlebox {
		display: block;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		line-height: 48rpx;
		margin-bottom: 15rpx;
	}

	.tipsbox {
		display: flex;
		align-items: center;
		font-size: 24rpx;
		color: #808080;
		margin-bottom: 20rpx;
	}

	.top-tag {
		color: #ff0000;
		padding: 2rpx 12rpx;
		border-radius: 12rpx;
		margin-right: 20rpx;
	}

	.author {
		margin-right: 20rpx;
	}

	.comments {
		margin-right: 20rpx;
	}

	.time {
		margin-left: auto;
	}

	.search-box {
		padding: 15rpx;
		background-color: #f5f5f5;
		border-radius: 15rpx;
	}

	.search-input {
		width: 100%;
		padding: 15rpx 20rpx;
		font-size: 26rpx;
		color: #333333;
	}
</style>